mx = 0
s = input()
a = [s[0], s[1], s[2], s[3], s[0:2], s[1:3], s[2:4], s[0:3], s[1:4], s]
for j in range(len(a)):
     с = 0
     n = int(input())
     for i in range(1, n+1):
          if n%i == 0:
                c = c + 1
                
     if  c == 2:
          mx = max(mx, n)
print(mx)     
